package com.ruoyi.employment.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.employment.domain.TEmploymentTrace;
import com.ruoyi.employment.service.ITEmploymentTraceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 就业跟踪Controller
 * 
 * @author ruoyi
 * @date 2022-12-24
 */
@RestController
@RequestMapping("/employmentTrace")
public class TEmploymentTraceController extends BaseController
{
    @Autowired
    private ITEmploymentTraceService tEmploymentTraceService;

    /**
     * 查询就业跟踪列表
     */
    @RequiresPermissions("employment:employmentTrace:list")
    @GetMapping("/list")
    public TableDataInfo list(TEmploymentTrace tEmploymentTrace)
    {
        startPage();
        List<TEmploymentTrace> list = tEmploymentTraceService.selectTEmploymentTraceList(tEmploymentTrace);
        return getDataTable(list);
    }

    /**
     * 导出就业跟踪列表
     */
    @RequiresPermissions("employment:employmentTrace:export")
    @Log(title = "就业跟踪", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TEmploymentTrace tEmploymentTrace)
    {
        List<TEmploymentTrace> list = tEmploymentTraceService.selectTEmploymentTraceList(tEmploymentTrace);
        ExcelUtil<TEmploymentTrace> util = new ExcelUtil<TEmploymentTrace>(TEmploymentTrace.class);
        util.exportExcel(response, list, "就业跟踪数据");
    }

    /**
     * 获取就业跟踪详细信息
     */
    @RequiresPermissions("employment:employmentTrace:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tEmploymentTraceService.selectTEmploymentTraceById(id));
    }

    /**
     * 新增就业跟踪
     */
    @RequiresPermissions("employment:employmentTrace:add")
    @Log(title = "就业跟踪", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TEmploymentTrace tEmploymentTrace)
    {
        return toAjax(tEmploymentTraceService.insertTEmploymentTrace(tEmploymentTrace));
    }

    /**
     * 修改就业跟踪
     */
    @RequiresPermissions("employment:employmentTrace:edit")
    @Log(title = "就业跟踪", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TEmploymentTrace tEmploymentTrace)
    {
        return toAjax(tEmploymentTraceService.updateTEmploymentTrace(tEmploymentTrace));
    }

    /**
     * 删除就业跟踪
     */
    @RequiresPermissions("employment:employmentTrace:remove")
    @Log(title = "就业跟踪", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tEmploymentTraceService.deleteTEmploymentTraceByIds(ids));
    }

    /**
     * 批量新增
     * @param tEmploymentTrace
     * @return
     */
    @Log(title = "就业跟踪", businessType = BusinessType.DELETE)
    @PostMapping("/addBatch")
    public AjaxResult addBatch(@RequestBody TEmploymentTrace tEmploymentTrace)
    {
        tEmploymentTraceService.addBatch(tEmploymentTrace);
        return AjaxResult.success();
    }
}
